zUI:RegisterComponent("zXp", "经验条(双倍信息)", function()
    local function GetRestXP()
        local xpMax = UnitXPMax("player")
        local xpRest = GetXPExhaustion()
        local restXP
        if xpRest and xpMax and (xpMax ~= 0) then
            restXP = " 双倍: " .. (math.floor(20 * xpRest / xpMax + 0.5)) .. "/30"
        else
            restXP = " 双倍: 0/30"
        end
        return restXP
    end

    function zXpTextStatusBar_UpdateTextString(textStatusBar)
        if (textStatusBar) then
            local name = textStatusBar:GetName();
            if name == "MainMenuExpBar" then
                zPrint("name = " .. name);
                local string = textStatusBar.TextString;
                if string then
                    local value              = textStatusBar:GetValue();
                    local valueMin, valueMax = textStatusBar:GetMinMaxValues();
                    local percent            = math.floor(value / valueMax * 100);
                    if (valueMax > 0) then
                        textStatusBar:Show();
                        if (value == 0 and textStatusBar.zeroText) then
                            string:SetText(textStatusBar.zeroText);
                            textStatusBar.isZero = 1;
                            string:Show();
                        else
                            textStatusBar.isZero = nil;
                            if textStatusBar:GetName() == "MainMenuExpBar" then
                                local restXp = GetRestXP();
                                if (C.unitframes.percentages == "1") then
                                    string:SetText("当前：" .. percent .. '%' .. restXp);
                                else
                                    string:SetText("当前：" .. true_format(value) .. '/' .. true_format(valueMax) .. restXp);
                                end
                                string:Show();
                            end
                        end
                    else
                        textStatusBar:Hide();
                    end
                    return -- should not run original function.
                end
            end
        end

        if (not textStatusBar) then
            textStatusBar = this;
        end
        local string = textStatusBar.TextString;
        if (string) then
            local restXp             = GetRestXP();
            local value              = textStatusBar:GetValue();
            local valueMin, valueMax = textStatusBar:GetMinMaxValues();
            local percent            = math.floor(value / valueMax * 100);
            local pp                 = UnitPowerType("player")
            local _, class           = UnitClass("player")
            if (C.unitframes.coloredtext == "1") then
                if textStatusBar:GetName() == 'PlayerFrameManaBar' or textStatusBar:GetName() == 'TargetFrameManaBar' then
                    if class == 'ROGUE' or (class == 'DRUID' and pp == 3) then
                        string:SetTextColor(250 / 255, 240 / 255, 200 / 255)
                    elseif class == 'WARRIOR' or (class == 'DRUID' and pp == 1) then
                        string:SetTextColor(250 / 255, 108 / 255, 108 / 255)
                    else
                        string:SetTextColor(.6, .65, 1)
                    end
                elseif textStatusBar:GetName() == 'PlayerFrameHealthBar' then
                    zUI.api.zGradient(math.floor(value), string, valueMin, valueMax)
                end
            end
            if (valueMax > 0) then
                textStatusBar:Show();
                if (value == 0 and textStatusBar.zeroText) then
                    string:SetText(textStatusBar.zeroText);
                    textStatusBar.isZero = 1;
                    string:Show();
                else
                    textStatusBar.isZero = nil;
                    if (C.unitframes.percentages == "1") then
                        if textStatusBar:GetName() == "MainMenuExpBar" then
                            string:SetText("当前：" .. percent .. '%' .. restXp);
                        else
                            string:SetText(percent .. '%')
                        end
                    else
                        if textStatusBar:GetName() == "MainMenuExpBar" then
                            string:SetText("当前：" .. true_format(value) .. '/' .. true_format(valueMax) .. restXp);
                        else
                            string:SetText(true_format(value))
                            --string:SetText(true_format(value) .. '/' .. true_format(valueMax))
                        end
                    end
                    -- Modified by shines77, 2023-09-18
                    if textStatusBar:GetName() == "MainMenuExpBar" then
                        string:Show();
                        return -- should not run original function.
                    else
                        if (GetCVar("statusBarText") == "1" and textStatusBar.textLockable) then
                            string:Show();
                        elseif (textStatusBar.lockShow > 0) then
                            string:Show();
                        else
                            string:Hide();
                        end
                    end
                end
            else
                textStatusBar:Hide();
            end
        end
    end

    zUI.api.hooksecurefunc("zUI", "TextStatusBar_UpdateTextString", zXpTextStatusBar_UpdateTextString, true);

    local f = CreateFrame("Frame");

    f:SetScript('OnEvent', function(self, event, arg1)
        if (event == "ADDON_LOADED" or event == "PLAYER_ENTERING_WORLD") then
            zPrint("event = "..event);
            if (MainMenuExpBar and MainMenuExpBar:IsShown()) then
                zXpTextStatusBar_UpdateTextString(MainMenuExpBar)
            end
        elseif (event == "PLAYER_XP_UPDATE" or event == "UPDATE_FACTION" or event == "PLAYER_AURAS_CHANGED") then
            zPrint("event = "..event);
            if (MainMenuExpBar and MainMenuExpBar:IsShown()) then
                zXpTextStatusBar_UpdateTextString(MainMenuExpBar)
            end
        end
    end)

    f:RegisterEvent('PLAYER_ENTERING_WORLD')
    f:RegisterEvent('ADDON_LOADED')

    f:RegisterEvent("PLAYER_XP_UPDATE");
    f:RegisterEvent("UPDATE_FACTION");
    f:RegisterEvent("PLAYER_AURAS_CHANGED");
end)
